package com.zjxny.proxy;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.zjxny.model.AccountInfo;

import cn.hutool.core.util.StrUtil;
import xyz.erupt.annotation.config.Comment;
import xyz.erupt.annotation.fun.DataProxy;

@Service
public class AccountProxy implements DataProxy<AccountInfo>{
	
	@Resource
	JdbcTemplate jdbcTemplate;
	
	@Override
	public void beforeAdd(@Comment("Erupt类对象") AccountInfo model) {
		//获取企业微信
	}

	//编辑时如果有cookie且和旧的不相同则直接更新状态为有效
	@Override
	public void beforeUpdate(@Comment("Erupt类对象") AccountInfo model) {
		if(StrUtil.isNotBlank(model.getCookies())) {
			String cookies = jdbcTemplate.queryForObject("select cookies from account_info where id="+model.getId(),String.class);
			if(!model.getCookies().equals(cookies)) {
				model.setIsValid(true);//置为有效
				model.setTaskStatus(true);//重新开启任务
			}
		} else {
			model.setIsValid(false);
			model.setTaskStatus(false);
		}
	}

	@Override
	public void afterUpdate(@Comment("Erupt类对象") AccountInfo model) {
//		jdbcTemplate.update("update car_info set is_");
	}
	
}